package ch.elca.lol.puissance4.player.net;

import ch.elca.lol.puissance4.game.Token;
import ch.elca.lol.puissance4.player.Player;

// TODO: server cannot be used with UI, why ?
public class Server extends Networker implements Player {
	public Server() {
		super(true);
	}
	
	@Override
	public void setToken(Token t) {
		log("negotiating token.");
		// Send own token
		writeInt(t.ordinal());
		
		// Read client token
		int read = readInt();
		
		if(read == t.ordinal()) {
			log("token mismatch.");
			close();
			throw new RuntimeException("Client token mismatch.");
		} else {
			log("token negotiation successful.");
		}
	}
}
